from classfile.attribute_info import AttributeInfo


class EnclosingMethodAttribute(AttributeInfo):
    def __init__(self, constPool):
        super().__init__()
        self.constantPool = constPool
        self.classIndex = 0
        self.methodIndex = 0

    def readInfo(self, clsReader):
        self.classIndex = int.from_bytes(clsReader.readU16(), "big")
        self.methodIndex = int.from_bytes(clsReader.readU16(), "big")

    @property
    def className(self):
        return self.constantPool.getClassName(self.classIndex)
    
    @property
    def methodNameAndDescriptor(self):
        if self.methodIndex:
            return self.constantPool.getNameAndType(self.methodIndex)
        return "", ""
